/*
 * Created by JFormDesigner on Sat Jan 03 23:01:17 EET 2009
 */

package joodle.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import joodle.si.ResourceManager;

/**
 * This class is the representation of the "Settings" menu choice on the menu bar
 */
@SuppressWarnings("serial")
public class SettingsDialog extends JDialog {
	private JoodleFrame owner;
	
	public SettingsDialog(JoodleFrame owner) {
		super(owner, ResourceManager.message("SETTINGS"));
		
		this.owner = owner;
		initComponents();
	}

	/**
	 * Initialized the basic components of "Settings" button
	 */
	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		drawGridCheck = new JCheckBox();
		sanpCheck = new JCheckBox();
		label1 = new JLabel();
		langBox = new JComboBox(new String[] { "English", "Turkce" });
		buttonBar = new JPanel();
		okButton = new JButton();
		cancelButton = new JButton();

		sanpCheck.setSelected(CanvasComponent.instance().isSnapOn());
		drawGridCheck.setSelected(CanvasComponent.instance().isGridOn());
		langBox.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent ae) {
				ResourceManager.setLocale(new Locale(
						langBox.getSelectedIndex() == 0 ? "US" : "TR"));
				owner.resetTexts();
			}
			
		});

		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new GridBagLayout());
				((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0};
				((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0};
				((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0E-4};
				((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4};

				//---- drawGridCheck ----
				drawGridCheck.setText("Draw grids");
				contentPanel.add(drawGridCheck, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 5), 0, 0));

				//---- sanpCheck ----
				sanpCheck.setText("Snap to Grid");
				contentPanel.add(sanpCheck, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 5), 0, 0));

				//---- label1 ----
				label1.setText("Language");
				contentPanel.add(label1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 5), 0, 0));
				contentPanel.add(langBox, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 5, 0), 0, 0));
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

				//---- okButton ----
				okButton.setAction(new AbstractAction(ResourceManager.message("OK")) {

					@Override
					public void actionPerformed(ActionEvent ae) {
						CanvasComponent.instance().setGrid(drawGridCheck.isSelected());
						CanvasComponent.instance().setSnap(sanpCheck.isSelected());
						CanvasComponent.instance().repaint();
						SettingsDialog.this.dispose();
					}
				});
				buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 5), 0, 0));

				//---- cancelButton ----
				cancelButton.setAction(new AbstractAction(ResourceManager.message("CANCEL")) {
					
					@Override
					public void actionPerformed(ActionEvent arg0) {
						SettingsDialog.this.dispose();
					}
					
				});
				
				buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JCheckBox drawGridCheck;
	private JCheckBox sanpCheck;
	private JLabel label1;
	private JComboBox langBox;
	private JPanel buttonBar;
	private JButton okButton;
	private JButton cancelButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
